#!/bin/sh

SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/ctl_common.sh"

SAPPHIRE_USER=`/usr/bin/whoami`; export SAPPHIRE_USER

if [ -z "${OVERRIDE_VERSION_STATUS}" ]; then
	case "${SAPPHIRE_USER}" in
		a_blue)
			SAPPHIRE_VERSION_STATUS="prod"
			;;
		a_blueu)
			SAPPHIRE_VERSION_STATUS="uat"
			;;
		a_blued)
			SAPPHIRE_VERSION_STATUS="dev"
			;;
		*)
			SAPPHIRE_VERSION_STATUS="dev"
			;;
	esac
else
	SAPPHIRE_VERSION_STATUS="${OVERRIDE_VERSION_STATUS}"
fi

BASE_DIR=`pwd`

export SAPPHIRE_LOG_DIR=${BASE_DIR}/logs/Sapphire
export SAPPHIRE_APP_DIR=${BASE_DIR}/apps
export SAPPHIRE_DATA_DIR=${BASE_DIR}/data
export SAPPHIRE_CONFIG_DIR=${BASE_DIR}/config
export SAPPHIRE_RUNTIME_DIR=${BASE_DIR}/runtime
export SAP_PRICING_VERSION=PricingServer
export SAPPHIRE_VERSION_STATUS
export TOPAZ_SAPPHIRE_SERVICES
export ALIB_KEY=${CONFIG_DIR}/alibkeys;

export CBB_CLIENT_LIB=${BASE_DIR}/SouthBeach4.6
export SB_HOME=${CBB_CLIENT_LIB}/client/lib
export EGO_CONFDIR=${CBB_CLIENT_LIB}/SOAM/conf
export SOAM_HOME=${CBB_CLIENT_LIB}/SOAM/conf
export SOAM_LIB=${CBB_CLIENT_LIB}/SOAM/lib
export SAPPHIRE_MACHINE_LOCATION="DEV"

######### Sapphire Global #########
export BLUE_USER_DIR=${SAPPHIRE_LOG_DIR}/
export LOG4J_LOC=${SAPPHIRE_CONFIG_DIR}/log4j.xml
export SAPPHIRE_VERSION_PROPERTIES="${SAP_REGION}ServerNonProd"
export SAPPHIRE_VERSION_PROPERTIES_RISK="${SAP_REGION}RiskServerNonProd"



export SAPPHIRE_HOME=/cygdrive/c/Work/Projects/Sapphire/services/local-sapphire-server

export QPID_PORT=11531
export QPID_JMX_PORT=3031
export SAPPHIRE_NUMBER_PRICING_SERVER=0
export SAPPHIRE_NUMBER_RISK_SERVER=1

export SAPPHIRE_RUNTIME_DIR=${SAPPHIRE_HOME}/runtime
export SAPPHIRE_RUNNING_SERVERS_FILE=${SAPPHIRE_RUNTIME_DIR}/server.pid
export SAPPHIRE_LOC=${SAPPHIRE_HOME}/sapphire-resources/${SAPPHIRE_CURRENT_VERSION}
export SAPPHIRE_SCRIPTS_LOC=${SAPPHIRE_LOC}/config/servers
export SAPPHIRE_GEMFIRE_PROP_FILE=${SAPPHIRE_LOC}/config/global/cbb/gemfire.properties
export SAPPHIRE_GEMFIRE_CACHE_FILE="${SAPPHIRE_LOC}/config/global/cbb/cache_prod_$(tr [A-Z] [a-z] <<< "$SAP_REGION").xml"
export BLUE_USER_DIR=${BLUE_USER_DIR}/${SAP_PRICING_VERSION}/

export SAP_LOG4J_LOC_PREFIX=${SAPPHIRE_LOG_DIR}/${SAP_PRICING_VERSION}/${DESK}_

export SAPPHIRE_QUEUE_PREFIX="SapphireServer_DEV"
export SAPPHIRE_LIVE_QUEUE_PREFIX="_Live"
export SAPPHIRE_CLOSE_QUEUE_PREFIX="_Close"
export SAPPHIRE_SOD_QUEUE_PREFIX="_SOD"
export SAPPHIRE_RISK_QUEUE_SUFFIX="_RiskQ"

export SAPPHIRE_LIVE_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..10}${SAPPHIRE_LIVE_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_CLOSE_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..10}${SAPPHIRE_CLOSE_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_SOD_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..10}${SAPPHIRE_SOD_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_COMPLETE_RISK_QUEUE="${SAPPHIRE_LIVE_RISK_QUEUE},${SAPPHIRE_CLOSE_RISK_QUEUE},${SAPPHIRE_SOD_RISK_QUEUE}"
export SAPPHIRE_RISK_QUEUE=`echo ${SAPPHIRE_COMPLETE_RISK_QUEUE} | sed 's/ //g' | sed 's/,,/,/g' | sed 's/\(.*\)./\1/g'`

export JAVA_OPTS="${JAVA_OPTS} -DmachineLocation=${SAPPHIRE_MACHINE_LOCATION}"
export JAVA_OPTS="${JAVA_OPTS} -DSAP_LOG4J_LOC_PREFIX=${SAP_LOG4J_LOC_PREFIX}"
export JAVA_OPTS="${JAVA_OPTS} -DTransportPort=${QPID_PORT} -Dxsd.validation=false"
export JAVA_CBB_OPTS="-DgemfirePropertyFile=${SAPPHIRE_GEMFIRE_PROP_FILE} -Dgemfire.cache-xml-file=${SAPPHIRE_GEMFIRE_CACHE_FILE} -DUseCBBForCurveTweaks=false"
export BLUE_VERSION_PATH="${SAPPHIRE_LOC}/config/servers/blueversion"
